module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        uglify: { 
            options: { 
                compress: {
                    // 压缩时删除 console.log 调试信息
                    drop_console: true 
                } 
            } 
        },
        useminPrepare: {
            html: 'src/index.html',
            options: {
                dest: 'dist'
            }
        },
        usemin: {
            html: ['dist/index.html']
        },
        copy: {
            images: {expand: true, cwd: 'src/assets/image/', src: '*', dest: 'dist/assets/image/'},
            main: { src: 'src/index.html', dest: 'dist/index.html' }
        },
        html2js: {
            options: { // 可选
                module: 'app', // 主 module 的名称
                rename: function(moduleName) { // 模板 module 名称
                    return moduleName;//.replace('', '')
                },
                singleModule: true, // 设置为 true 时，只使用 主 module
                existingModule : true,
                htmlmin: {
                    collapseBooleanAttributes: true,
                    collapseWhitespace: true,
                    removeAttributeQuotes: true,
                    removeComments: true,
                    removeEmptyAttributes: true,
                    removeRedundantAttributes: true,
                    removeScriptTypeAttributes: true,
                    removeStyleLinkTypeAttributes: true
                },
                watch: true
            },
            main: {
                src: ['src/app/components/*/*.html'],
                dest: 'dist/js/templates.js'
            },
        },

        watch: {
            html : {
                files: ['src/index.html'] // 这里不需要执行命令
            },
            livereload: {
                options: { livereload: 35730 },
                files: ['src/**/*'] // 当此目录下的文件发生变化时，就通知刷新
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-usemin');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-html2js');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('build', [
        'copy:images',
        'copy:main',
        'useminPrepare',
        'concat',
        'uglify',
        'cssmin',
        'usemin',
        'html2js:main'
    ]);
    grunt.registerTask('default', ['watch']);
};
